﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.BasicData.Api.Application.Command.Accont;
using SmartCity.BasicData.Api.DTOs;
using SmartCity.BasicData.ErrorCoce;

namespace SmartCity.BasicData.Api.Controllers
{
    /// <summary>
    /// 账号控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;

        public AccountController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="request">请求命令</param>
        /// <returns></returns>
        [HttpPost]
        public  Task<ApiResult<LoginDTO>> Login(LoginAccountCommand request) {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据部门id查找部门下所有账号
        /// </summary>
        /// <param name="request">部门id</param>
        /// <returns>Apiresult 包装的账号列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<AccountFromDepartmentDTO>>> GetDeptAccounts([FromQuery]GetDeptAccountCommand request) { 
        return await mediator.Send(request);
        }
    }
}
